package hlhj.fhp.checkpoint.module

import android.content.Context
import com.example.mymvp.log
import com.example.mymvp.mvp.BaseModule
import com.lzy.okgo.model.Response
import hlhj.fhp.checkpoint.http.Apis
import hlhj.fhp.checkpoint.http.CustomAction
import hlhj.fhp.checkpoint.http.LoadingAction
import hlhj.fhp.checkpoint.javaBean.MyBaseBean
import hlhj.fhp.checkpoint.javaBean.UserInfoBean

/**
 * Created by Never Fear   on 2018\11\7 0007.
Never More....
 */
class HomeSelfModule :BaseModule {

    var listener:UserInfoResp?=null
    fun loginOut(c:Context){
        Apis.loginOut()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<MyBaseBean>>(c){
                                override fun httpSuccess(t: Response<MyBaseBean>) {
                                    listener?.setLoginOut(t.body())
                                }
                            })
                }
    }
    fun getUserInfo(c:Context){
        Apis.getUserInfo()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<UserInfoBean>>(c){
                                override fun httpSuccess(t: Response<UserInfoBean>) {
                                    log("","缓存里来的数据${t.body().info.balance}")
                                    listener?.infoResp(t.body())
                                }

                                override fun acheSuccess(t: Response<UserInfoBean>) {
                                    listener?.infoResp(t.body())
                                }
                            })

                }
    }

    interface UserInfoResp{
        fun infoResp(userInfoBean: UserInfoBean)

        fun setLoginOut(myBaseBean: MyBaseBean)
    }
}